from django.db import models
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
# Create your models here.


class Contact(models.Model):
    first_name = models.CharField(max_length=64)
    last_name = models.CharField(max_length=64)
    email = models.EmailField()
    owner = models.ForeignKey(User, null=True)
    def __unicode__(self):
        return ' '.join((self.first_name, self.last_name))

    def get_absolute_url(self):
        return reverse('contact-detail', kwargs={'pk': self.id})


class Address(models.Model):
    contact = models.ForeignKey(Contact)
    address_type = models.CharField(max_length=10)
    address = models.CharField(max_length=255)
    city = models.CharField(max_length=64)
    state = models.CharField(max_length=2)
    post_code = models.CharField(max_length=20)

    class Meta:
        unique_together = ('contact', 'address_type')

    def __unicode__(self):
        return ', '.join((self.post_code, self.address, self.city, self.state))
